package com.tlgen.controller;

import com.tlgen.config.VerificationCode;
import com.tlgen.model.RespBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @author: tlgen
 * @Discription:
 */
@RestController
public class LoginController {

    @GetMapping("/login")
    public RespBean login() {
        return RespBean.error("尚未登录， 请登录!");
    }

    //验证码图片生成的接口 验证码不需要登录就可以访问 需要配置不需要拦截的请求
    @GetMapping("/verifyCode")
    public void verifyCode(HttpSession session, HttpServletResponse response) throws IOException {
        VerificationCode code = new VerificationCode(); //直接new出一个验证码
        BufferedImage image = code.getImage(); //获取图片
        String text = code.getText(); //获取文字
        session.setAttribute("verify_code", text); //文字要存到session哩边去
        VerificationCode.output(image,response.getOutputStream()); //然后把图片输出出去
    }

}
